home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1171 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: abell@mindspring.com (Andrew Bell)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Is RTTI required if polymorphic constructor exists
  5. Date: 19 Apr 1996 14:43:45 GMT
  6. Organization: MindSpring Enterprises
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4l72i4$1js6@mule1.mindspring.com>
  9. References: <4kng7f$kt9@nuscc.nus.sg>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. X-Nntp-Posting-Host: abell.mindspring.com
  12. X-Newsreader: Forte Agent .99.82
  13. Content-Length: 1388
  14. X-Lines: 33
  15. Originator: clamage@taumet
  16.  
  17. satrajit@iscs.nus.sg (Satrajit Sujit Ghosh) wrote:
  18. >    If a polymorphic constructor can be created as demonstrated below, 
  19. >is RTTI really necessary, considering that it does not really provide a 
  20. >great deal of information.
  21.  
  22. I don't understand particularly how your sample code makes RTTI less
  23. useful.  One place RTTI is handy is if you have an interaction between
  24. two classes, where knowing the exact type of each class can lead to
  25. optimizations.
  26.  
  27. For example, you might have a generic bitmap class, which returns an
  28. RGB value for each pixel, and you want to copy one bitmap to another.
  29. A derived class from your bitmap class might be a class that
  30. represents a 256 color bitmap, with an overloaded copy operator.  If
  31. you leave the bitmap you're copying as the generic type, then you need
  32. to obtain the RGB value for a pixel, find the closest match in your
  33. palette, and assign the pixel that palette index.  But if you know the
  34. bitmap you're copying from is also a 256 color bitmap, you can build a
  35. conversion table between matching palette indices, and do a much
  36. faster copy.*
  37.  
  38. One problem, though, is that you may not care about the actual class
  39. of an object, but just whether it is derived from (or is) of a
  40. particular class, and RTTI doesn't help you there.
  41.  
  42. Andrew Bell
  43. abell@mindspring.com
  44.  
  45. * For real quality, you want to dither your data, and thus this
  46. algorithm wouldn't hold.
  47.  
  48.  
  49.  
  50.  
  51.  
  52. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  53. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  54. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  55. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  56. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  57.